﻿/***************************************************************************
 * 文件名：Bank
 * 功能：
 * 说明：
 * -------------------------------------------------------------------------
 * 创建时间：2024/5/22 9:56:17
 * 创建人：林远
 * 邮箱： 17682102673@qq.com
 * =========================================================================
 *
 * 修改人：   
 * 修改时间：   
 * 修改说明：   
 ***************************************************************************/
using BankAccValidator.BankBus;

namespace MySystem.Static
{
    /// <summary>
    /// 银行常量
    /// </summary>
    public class BankConst
    {
        /// <summary>
        /// 中国工商银行
        /// </summary>
        public const string ICBC = "ICBC";

        /// <summary>
        /// 中国银联
        /// </summary>
        public const string ChinaUnionPay = "ChinaUnionPay";

        private static readonly Dictionary<string, string> _names = new Dictionary<string, string>
        {
            { ICBC,"中国工商银行"},
            { ChinaUnionPay,"中国银联"},
        };

        /// <summary>
        /// 获取银行名称
        /// </summary>
        /// <param name="bank"></param>
        /// <returns></returns>
        public static string GetName(string bank)
        {
            return _names.ContainsKey(bank) ? _names[bank] : string.Empty;
        }

        public static bool ContaisKey(string bank)
        {
            return _names.ContainsKey(bank);
        }
    }

    /// <summary>
    /// 银行业务类型常量
    /// </summary>
    public class BankBusTypeConst
    {
        /// <summary>
        /// 账户验证
        /// </summary>
        public const string B01 = "01";

        /// <summary>
        /// 其它业务
        /// </summary>
        public const string B999 = "999";

        public static readonly Dictionary<string, string> _names = new Dictionary<string, string>
        {
            { B01,"账户验证"},
            { B999,"其它"},
        };

        /// <summary>
        /// 获取业务名称
        /// </summary>
        /// <param name="">业务类型</param>
        /// <returns></returns>
        public static string GetName(string busType)
        {
            return _names.ContainsKey(busType) ? _names[busType] : string.Empty;
        }

        public static bool ContainsKey(string key)
        {
            return _names.ContainsKey(key);
        }
    }

    /// <summary>
    /// 银行接口常量
    /// </summary>
    internal class BankInterfaceUrlConst
    {
        #region Url Const

        /// <summary>
        /// 用来测试的哔哩哔哩银行接口
        /// </summary>
        private const string TestUrl = @"www.bilibili.com";

        /// <summary>
        /// 中国银联银行账户验证接口
        /// </summary>
        private const string ChinaUnionPay_AccVerify = @"https://auth.95516.com/authonl/onlineAuth/rest/verify/bankcard";

        #endregion

        #region Map

        private static readonly Dictionary<KeyValuePair<string, string>, string> _names = new Dictionary<KeyValuePair<string, string>, string>
        {
            { new KeyValuePair<string, string> (BankConst.ChinaUnionPay,BankBusTypeConst.B01),ChinaUnionPay_AccVerify},
        };

        private static readonly Dictionary<string, Type> _interfacePostParamDir = new Dictionary<string, Type>
        {
            { ChinaUnionPay_AccVerify,typeof(ChinaUnion_B01PostParam)},
        };

        private static readonly Dictionary<string, Type> _interfaceResultTypeDir = new Dictionary<string, Type>
        {
            {ChinaUnionPay_AccVerify,typeof(ChinaUnion_B01PostResult) }
        };

        #endregion

        #region Methods

        /// <summary>
        /// 获取银行对应业务的接口地址
        /// </summary>
        /// <param name="bank">银行</param>
        /// <param name="bankBusType">业务类型</param>
        /// <returns></returns>
        public static string GetBusInterfaceUrl(string bank, string bankBusType)
        {
            return _names.ContainsKey(new KeyValuePair<string, string>(bank, bankBusType)) ? _names[new KeyValuePair<string, string>(bank, bankBusType)] : string.Empty;
        }

        /// <summary>
        /// 获取是否配置了银行对应业务
        /// </summary>
        /// <param name="bank"></param>
        /// <param name="busType"></param>
        /// <returns></returns>
        public static bool ContainsKey(string bank, string busType)
        {
            return _names.ContainsKey(new KeyValuePair<string, string>(bank, busType));
        }

        public static Type GetBusPostParamType(string bank, string busType)
        {
            var url = GetBusInterfaceUrl(bank, busType);
            if (string.IsNullOrEmpty(url))
            {
                return typeof(object);
            }
            return _interfacePostParamDir[url];
        }

        /// <summary>
        /// 获取银行业务对应返回类型
        /// </summary>
        /// <param name="bank"></param>
        /// <param name="busType"></param>
        /// <returns></returns>
        public static Type GetBusResultType(string bank, string busType)
        {
            var url = GetBusInterfaceUrl(bank, busType);
            if (string.IsNullOrWhiteSpace(url))
            {
                return typeof(object);
            }
            return _interfaceResultTypeDir[url];
        }

        #endregion
    }
}